import dts from "vite-plugin-dts";
import { defineConfig } from "vite";
import vueJsx from '@vitejs/plugin-vue-jsx';
import vue from "@vitejs/plugin-vue";
import path from "path";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueJsx(),
    dts({
      //指定使用的tsconfig.json为我们整个项目根目录下掉,如果不配置,你也可以在components下新建tsconfig.json
      tsConfigFilePath: "./tsconfig.json",
    }),
    //因为这个插件默认打包到es下，我们想让lib目录下也生成声明文件需要再配置一个
    dts({
      outputDir: "lib",
      tsConfigFilePath: "./tsconfig.json",
    }),
  ],
  
  resolve: {
    alias: {
      // "@": fileURLToPath(new URL("./src", import.meta.url)),
    },
  },
  server:{
    host:"0.0.0.0"
  },
  build: {
    // cssCodeSplit: true,
    rollupOptions: {
      external: ["vue", "vue-router"],
      output: {
        inlineDynamicImports: true, //支持动态导入
        globals: {
          vue: "Vue",
          "vue-router": "VueRouter",
        },
      },
    },
    lib: {
      entry: path.join(__dirname, "./lib/index.ts"),
      name: "Ant3Ui",
      fileName: (format) => `ant3-ui.${format}.js`,
    },
    outDir: path.join(__dirname, "./lib"),
  },
});
